package com.wanjia.seal.manager.controller;

import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.entity.SysRole;
import com.wanjia.seal.manager.entity.SysRoleMenu;
import com.wanjia.seal.manager.mapper.SysRoleMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api")
@Api(tags = "角色")
@Slf4j
public class SysRoleController extends BaseController{

    @Autowired
    SysRoleMapper sysRoleMapper;


    @ResponseBody
    @GetMapping("/allrole")
    @ApiOperation(value = "查询所有角色", notes = "查询是否成功")
    @LoginToken
    public JsonResult<List<SysRole>> getAll() {
        List<SysRole> sysRoles = sysRoleMapper.selectList(null);
        return new JsonResult<>(OK,sysRoles);
    }

    @ResponseBody
    @GetMapping("/role")
    @ApiOperation(value = "用ID查询角色", notes = "查询是否成功")
    @LoginToken
    public JsonResult<SysRole> getById(Integer RoleId){
        SysRole sysRole = sysRoleMapper.selectById(RoleId);
        return new JsonResult<>(OK,sysRole);
    }
    @ResponseBody
    @PutMapping("/updaterole")
    @ApiOperation(value = "更新角色", notes = "更新角色是否成功")
    @LoginToken
    public JsonResult upData(@RequestBody SysRole sysRole){
        sysRoleMapper.updateById(sysRole);
        return new JsonResult(OK);
    }

    @ResponseBody
    @PostMapping("/addrole")
    @ApiOperation(value = "添加角色", notes = "添加角色是否成功")
    @LoginToken
    public JsonResult addRole(@RequestBody SysRole sysRole){
        sysRoleMapper.insert(sysRole);
        return new JsonResult(OK);
    }
    @ResponseBody
    @DeleteMapping("/deleterole")
    @ApiOperation(value = "删除角色", notes = "删除角色是否成功")
    @LoginToken
    public JsonResult update( Integer RoleId) {
        sysRoleMapper.deleteById(RoleId);
        return new JsonResult(OK);
    }


}
